package com.coreJava.bingfabao;

import java.util.concurrent.Semaphore;

/**
 * 作者: LCG
 * 日期: 2020/2/10 23:35
 * 描述:
 */
public class TestSem2 implements Runnable{
    private Semaphore semaphore;

    public TestSem2(Semaphore semaphore) {
        this.semaphore = semaphore;
    }

    @Override
    public void run() {

        try {
            semaphore.acquire();//获取不到就阻塞，获取到的话就向下执行
            Thread.sleep(3000);
            System.out.println("========="+Thread.currentThread().getName());
            semaphore.release();//释放资源

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
